package cn.fl.project.service.impl;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.preloan.enums.LogBusinessTypeEnum;
import cn.fl.project.condition.PrjQuatPrpsCfgDQueryCondition;
import cn.fl.project.dto.PrjQuatPrpsCfgDDTO;
import cn.fl.project.service.IPrjQuatPrpsCfgDService;
import cn.fl.project.service.IProjectApiService;
import cn.fl.project.transform.PrjQuatPrpsCfgDVOTransform;
import cn.fl.project.vo.PrjQuatPrpsCfgDVO;
import com.alibaba.fastjson.JSON;
import com.lionbridge.log.ext.ExtSlf4jLogger;
import com.lionbridge.log.ext.ExtSlf4jLoggerBuilder;
import com.lionbridge.log.ext.LogTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 项目报价方案配置明细信息表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Slf4j
@Service
public class PrjQuatPrpsCfgDServiceImpl implements IPrjQuatPrpsCfgDService {
	private static ExtSlf4jLogger logger = ExtSlf4jLoggerBuilder.create()
			.setLogger(log).setBusinessType(LogBusinessTypeEnum.QUOTATION_SCHEME.getCode())
			.setSubBusinessType(LogBusinessTypeEnum.QUOTATION_SCHEME.getCode())
			.setLogType(LogTypeEnum.BUSINESS).build().setKeywords("PrjQuatPrpsCfgD");
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private IProjectApiService projectApiService;

	@Override
	public PrjQuatPrpsCfgDVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			return null;
		}
		//TODO 业务逻辑
		PrjQuatPrpsCfgDDTO dto = null;//this.自定义ApiService.selectById(id);
		return PrjQuatPrpsCfgDVOTransform.toVO(dto);
	}

	@Override
	public Long add(PrjQuatPrpsCfgDVO entity) throws BaseException{
		if(null == entity){
			return null;
		}
		//return this.prjQuatPrpsCfgDApiService.add(PrjQuatPrpsCfgDVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return null;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			return false;
		}
		//return this.prjQuatPrpsCfgDApiService.removeById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(PrjQuatPrpsCfgDVO entity) throws BaseException{
		if(null == entity){
			return false;
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "缺少必要条件:方案ID");
		}
		PrjQuatPrpsCfgDQueryCondition qc = (PrjQuatPrpsCfgDQueryCondition) page.getCondition();
		if(qc == null || qc.getPrpsCfgId() ==null){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "缺少必要条件:方案ID");
		}
		logger.info("initList方案费用项初始化.请求参数page:{}",JSON.toJSONString(page));
		page = this.projectApiService.searchPrjQuatPrpsCfgDListPage(page, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		List<PrjQuatPrpsCfgDDTO> dtoList = (List<PrjQuatPrpsCfgDDTO>) page.getResultList();
		logger.info("initList方案费用项初始化.响应数据dtoList:{}",JSON.toJSONString(dtoList));
		page.setResultList(PrjQuatPrpsCfgDVOTransform.toVOList(dtoList));
		return page;
	}
}
